<?php
// +----------------------------------------------------------------------
// | 租户授权管理 类型服务
// +----------------------------------------------------------------------
// | 主要服务于租户成员授权管理数据处理
// +----------------------------------------------------------------------
// | 错误编码头 303xxx
// +----------------------------------------------------------------------

namespace common\service;

use common\model\TenantApplyModel;

class TenantApplyService
{
    /**
     * 获取申请列表
     * @param $userId
     * @param $params
     * @return mixed
     */
    public function getMyApply($userId, $params)
    {
        $data = $params['data'] ?? [];
        $page = "1, 20";
        if (array_key_exists('page', $data)) {
            $page = join(',', $data['page']);
        }

        $row = model(TenantApplyModel::class)->join('tenant ON tenant.id = tenant_apply.tenant_id', 'left')
            ->where(['tenant_apply.user_id' => $userId])
            ->field(['tenant_apply.tenant_id, tenant.name, tenant_apply.status, tenant_apply.created'])
            ->page($page)
            ->order("tenant_apply.id DESC")
            ->select();

        return [
            'row' => $row
        ];
    }
}